#include "../test_type.h"
#include "../../src/thread/RecursiveMutex.h"
#include "../../src/thread/Thread.h"

using namespace LibTools;

static int g_count = 0;

#define MAX_NUM_STOP 2000

DWORD func1(void *m)
{
	static int g_stop1 = 0;
	CLockGurad lk((CRecursiveMutex*)m);
	g_count++; g_stop1++;
	if(g_stop1 < MAX_NUM_STOP) func1(m);

	return 0;
}

DWORD func2(void *m)
{
	static int g_stop2 = 0;
	CLockGurad lk((CRecursiveMutex*)m);
	g_count++; g_stop2++;
	if(g_stop2 < MAX_NUM_STOP) func2(m);

	return 0;
}


#ifdef TEST_MUTEX
int main()
{
	CRecursiveMutex mutex;
	CThread t1(func1, &mutex);
	CThread t2(func2, &mutex);

	t1.Join();
	t2.Join();

	printf("g_count = %d\n", g_count);

	return 0;
}
#endif //TEST_MUTEX